﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;

namespace Royaumes_Libres.Database
{
    public class cAttack
    {

        public cAttack()
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="PkKingdomAtk"></param>
        /// <param name="PkKingdomDef"></param>
        /// <returns></returns>
        ///<remarks>Francis Gagne</remarks>
        public static int GetTimeTravel(int PkKingdomAtk, int PkKingdomDef)
        {
            SqlCommand cmd = cSQL.GetDbJeuCommand();
            int TimeTravel;

            try
            {
                cmd.Connection.Open();
                cmd.CommandText = "cde.spGetTimeTravel";
                cmd.Parameters.Add(cSQL.Param("@PkKingdomAtk", PkKingdomAtk, SqlDbType.Int));
                cmd.Parameters.Add(cSQL.Param("@PkKingdomDef", PkKingdomDef, SqlDbType.Int));

                TimeTravel = Convert.ToInt32(cmd.ExecuteScalar());

                cmd.Connection.Close();
                return TimeTravel;
            }
            catch(Exception ex)
            {
                cmd.Connection.Close();
                throw new Exception("cAttack.GetTimeTravel(): " + ex.Message);
            }

        }

        public static void Attack(int FkKingdomAtk, int NbWarrior, int NbArcher, int NbKnight, int NbPriest, int FkKingdomDef)
        {
            SqlCommand cmd = cSQL.GetDbJeuCommand();

            try
            {
                cmd.Connection.Open();
                cmd.CommandText = "cde.spCreateFight";
                cmd.Parameters.Add(cSQL.Param("@FkKingdomAtk", FkKingdomAtk, SqlDbType.Int));
                cmd.Parameters.Add(cSQL.Param("@NbWarrior", NbWarrior, SqlDbType.Int));
                cmd.Parameters.Add(cSQL.Param("@NbArcher", NbArcher, SqlDbType.Int));
                cmd.Parameters.Add(cSQL.Param("@NbKnight", NbKnight, SqlDbType.Int));
                cmd.Parameters.Add(cSQL.Param("@NbPriest", NbPriest, SqlDbType.Int));
                cmd.Parameters.Add(cSQL.Param("@FkKingdomDef", FkKingdomDef, SqlDbType.Int));
                cmd.ExecuteScalar();

                cmd.Connection.Close();
            }
            catch (Exception ex)
            {
                cmd.Connection.Close();
                throw new Exception("cAttack.Attack(): " + ex.Message);
            }
        }
    }
}